pp108 : Downloading a File from a Service

Downloading a File from a Service

This topic describes the procedure to download a file from a service.


At times, you may have to download files from a service while it is running, through a Web browser. To support this process, a HTML page is required that is programmed to download the required file. Process Platform provides you the required component to design such a page.

The component download.htm internally uses a template which is a HTML page. The component takes the content type and search path of the file that is to be downloaded. Additionally, it also takes the request SOAP message for the service from which the file will be downloaded, and submits it to a Java class called Download.wcp. This Java class sends the request message to the Process Platform Web Gateway which in turn sends it to the appropriate service. The file is then successfully downloaded from the intended service.

Note:

You need to exactly know which tag of the response SOAP message returned by the Gateway contains the file that is to be downloaded.

The following figure illustrates the way the download process works.



  1. Create a HTML page, fulfilling the following requirements:
    1. Add the script <script type=text/javascript src='/cordys/wcp/application.js'></script> to the page.
    2. Add the download component to the page as shown in the code:
      <div cordysType="wcp.library.util.download" id='downloader' request = sampleMessage.XMLDocument />

  2. Create a Web Service Operation GetResume that will be sent to the service, and add it to the page as shown in the example below
    <script id="sampleMessage" type="cordys/xml">
        <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
            <SOAP:Body>
                <GetResume xmlns="http://schemas.cordys.com/DownloadDemo">
                    <EmployeeID>PARAMETER</EmployeeID>
                </GetResume>
            </SOAP:Body>
        </SOAP:Envelope>
    </script>
    

  3. Set the following properties for the download component before you start downloading the file:
    • contentType - Specify the contentType of the file being downloaded. By default, this will be set to application or octect-stream. The following example sets the content type to a Microsoft Word file.
      downloader.contentType = 'application/msword'

    • searchPath - Specify the exact node or tag of the content that is being downloaded in the response message that is returned from the service. In the following example, the content of the <Resume> tag, which is a word document, is being downloaded.
      downloader.searchPath = '<Resume>';

  4. Add the downloadFile Web service operation to the page. Developing the HTML page is complete.
  5. Create a shortcut. For more information on creating a shortcut, refer to Creating a Shortcut using URL.

    Note:
    The URL for creating the shortcut is the URL for accessing the HTML page.

The HTML page to download a file from a service is created.

Note:

For more information on downloading a file from a service, refer to Download.

Related reference

Download